<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div id="app">
        <div>当前时间是： {{ dateTime }</div>
            <div>格式化后的时间是： {{ dateTime | dateFormat }}</div>
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                dateTime: new Date(),
            },
            // 定义一个局部的过滤器，格式化当前时间
            filters: {
                dateFormat: (now) => {
                    var y = now.getFullYear()
                    var m = (now.getMonth() + 1).toString().padStart(2, '0')
                    var d = now.getDate().toString().padStart(2, '0')
                    var hh = now.getHours().toString().padStart(2, '0')
                    var mm = now.getMinutes().toString().padStart(2, '0')
                    var ss = now.getSeconds().toString().padStart(2, '0')
                    // 过滤器中要有返回值
                    return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
                }
            }
        })
    </script>


</body>

</html>